package com.atkins.spring;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.atkins.spring.data.ILaneData;

@Controller
@RequestMapping(value="/backbone")
public class BackboneController {

	@Autowired
	ILaneData laneDataConnection;
	
	@RequestMapping(value="/" , method=RequestMethod.GET)
	public String main(Model model)
	{
		return "backbone/main";
	}
	
	@RequestMapping(value = "/getList", method = RequestMethod.GET, consumes="application/json", produces="application/json")
	public @ResponseBody List<ILaneData.LaneClosure> getList() {  
		System.out.println("Get lane list");  
		return laneDataConnection.getAllLaneClosures();
	}
	
	@RequestMapping(headers ={"Accept=application/json"}, value = "/save", method = { RequestMethod.POST, RequestMethod.PUT}, consumes="application/json")
	public @ResponseBody PostResponse editJSON(@RequestBody ILaneData.LaneClosure lc, Model model) {  
		
		laneDataConnection.add(lc);
		String resp = PostResponse.SUCCESS;
		return new PostResponse(resp);
	}
	
}
